package com.ruoyi.project.wms.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.wms.mapper.WmsWarehouseMapper;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.common.zx.PageData;
import com.ruoyi.project.wms.service.impl.WmsWarehouseServiceImpl;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 仓库配置Controller
 *
 * @author zx
 * @date 2023-05-25
 */
@RestController
@RequestMapping("/wms/warehouse")
public class WmsWarehouseController extends BaseController {
    @Autowired
    private WmsWarehouseServiceImpl wmsWarehouseService;

    @Autowired
    private WmsWarehouseMapper wmsWarehouseMapper;

    /**
     * 查询仓库配置列表
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:list')")
    @GetMapping("/list")
    public AjaxResult list() {
        PageData pd = this.getPageData();
        startPage();
        List<PageData> list = wmsWarehouseService.selectWmsWarehouseList(pd);
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('wms:warehouse:list')")
    @GetMapping("/listDeliveryName")
    public AjaxResult DeliveryName() {
        List<PageData> list = wmsWarehouseMapper.selectWmsWarehouseListDeliveryName();
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('wms:warehouse:list')")
    @GetMapping("/listName")
    public AjaxResult ListName() {
        List<PageData> list = wmsWarehouseMapper.selectWmsWarehouseListName();
        return success(list);
    }

    @PreAuthorize("@ss.hasPermi('wms:warehouse:list')")
    @GetMapping("/listReceiveName")
    public AjaxResult receiveName() {
        List<PageData> list = wmsWarehouseMapper.selectWmsWarehouseListreceiveName();
        return success(list);
    }


    /**
     * 导出仓库配置列表
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:export')")
    @Log(title = "仓库配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageData pd) {
        List<PageData> list = wmsWarehouseService.selectWmsWarehouseList(pd);
        ExcelUtil<PageData> util = new ExcelUtil<PageData>(PageData.class);
        util.exportExcel(response, list, "仓库配置数据");
    }

    /**
     * 获取仓库配置详细信息
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(wmsWarehouseService.selectWmsWarehouseById(id));
    }

    /**
     * 新增仓库配置
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:add')")
    @Log(title = "仓库配置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PageData pd) {
        return toAjax(wmsWarehouseService.insertWmsWarehouse(pd));
    }

    /**
     * 修改仓库配置
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:edit')")
    @Log(title = "仓库配置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PageData pd) {
        return toAjax(wmsWarehouseService.updateWmsWarehouse(pd));
    }

    /**
     * 删除仓库配置
     */
    @PreAuthorize("@ss.hasPermi('wms:warehouse:remove')")
    @Log(title = "仓库配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(wmsWarehouseService.deleteWmsWarehouseByIds(ids));
    }

    @GetMapping("/area")
    public AjaxResult getAreaWarehouse() {
        return AjaxResult.success(wmsWarehouseMapper.selectAreaWarehouse());
    }
}
